package WoidCount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * Created by yqz on 2019/3/29.
 */
public class WordCountPartitioner extends Partitioner<Text, IntWritable> {
    @Override
    public int getPartition(Text key, IntWritable intWritable, int partition) {
        //取电话号码前三位
        String num = key.toString().substring(0, 3);

        partition = 5;

        if ("134".equals(num)) {
            partition = 0;
        } else if ("135".equals(num)) {
            partition = 1;
        } else if ("136".equals(num)) {
            partition = 2;
        } else if ("137".equals(num)) {
            partition = 3;
        }else if ("138".equals(num)) {
            partition = 4;
        }else if ("139".equals(num)) {
            partition = 5;
        }

        return partition;
    }
}
